Skip to content

fix: support aliases in all OpenSearchDocumentStore methods#3336

Merged
tstadel merged 1 commit into
mainfrom
fix/opensearch_alias_support
May 20, 2026
Merged

fix: support aliases in all OpenSearchDocumentStore methods#3336
tstadel merged 1 commit into
mainfrom
fix/opensearch_alias_support

Conversation

@tstadel
Copy link
Copy Markdown
Member

@tstadel tstadel commented May 20, 2026

Related Issues

OpenSearch's indices.get_mapping() and indices.get() APIs always key their response by the real (concrete) index name, not by the alias name used in the request. Every call site that did mapping[self._index] would raise KeyError when self._index was an alias.

Proposed Changes:

document_store.py — 6 call sites fixed using actual_index = next(iter(response)):

  • _ensure_index_exists / _ensure_index_exists_async — reading mappings on startup
  • delete_all_documents / delete_all_documents_async — reading index settings before recreation
  • count_unique_metadata_by_filter / count_unique_metadata_by_filter_async — reading field mappings
  • get_metadata_fields_info / get_metadata_fields_info_async — reading field mappings

Alias guard for destructive recreation: delete_all_documents(recreate_index=True) now raises DocumentStoreError early when self._index is an alias. Deleting and recreating through an alias would drop the backing index and create a new concrete index named after the alias, permanently breaking the alias relationship. The recreate_index=False (delete-by-query) path is unaffected and works normally with aliases.

How did you test it?

Unit tests (mocked):

  • test_delete_all_documents_recreate_raises_for_alias / _works_for_concrete_index (sync + async variants)
  • test_ensure_index_exists_{direct_index,with_alias,creates_index,no_create} (sync + async variants, added in prior commits)

Integration tests:

  • test_document_store_with_alias / test_document_store_async_with_alias — basic read/write via alias
  • test_delete_all_documents_with_alias / async — asserts DocumentStoreError with recreate_index=True
  • test_delete_all_documents_no_recreate_with_alias / async — verifies delete-by-query clears all docs and index remains writable
  • test_count_unique_metadata_by_filter_with_alias / async — mapping lookup works through alias
  • test_get_metadata_fields_info_with_alias / async — mapping lookup works through alias

Notes for the reviewer

Checklist

@tstadel tstadel requested a review from a team as a code owner May 20, 2026 09:27
@tstadel tstadel requested review from davidsbatista and removed request for a team May 20, 2026 09:27
@github-actions github-actions Bot added integration:opensearch type:documentation Improvements or additions to documentation labels May 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Coverage report (opensearch)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  integrations/opensearch/src/haystack_integrations/document_stores/opensearch
  document_store.py 1837-1842, 1881-1886, 1932-1939, 1966-1973
Project Total  

This report was generated by python-coverage-comment-action

Copy link
Copy Markdown
Contributor

@davidsbatista davidsbatista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@tstadel tstadel merged commit ec282dc into main May 20, 2026
12 checks passed
@tstadel tstadel deleted the fix/opensearch_alias_support branch May 20, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration:opensearch type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants